﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biosek.Core;
using System.IO;

public static class ARFFHelper
{
	public static void SavePositiveAndNegativeARFF(string filename, PlainSequenceSet positiveSamples, PlainSequenceSet negativeSamples)
	{
		using (var sb = new StreamWriter(filename))
		{
			sb.WriteLine("@RELATION cleavageSite_chainPairs");
			var mp = positiveSamples.Concat(negativeSamples).Select(x => x.Length).Max();
			for (int i = 0; i < mp; i++)
			{
				sb.WriteLine("@ATTRIBUTE c{0} NUMERIC", i);
			}
			const string sptag = "p";
			const string sntag = "n";
			sb.WriteLine("@ATTRIBUTE class {{{0},{1}}}", sptag, sntag);
			sb.WriteLine("@DATA");
			var ptag = new[] { sptag };
			var ntag = new[] { sntag };
			foreach (var item in positiveSamples)
			{
				var r = item.Select(x => x.ToString().PadLeft(2)).Concat(ptag);
				var line = string.Join(",", r);
				sb.WriteLine(line);
			}
			foreach (var item in negativeSamples)
			{
				var r = item.Select(x => x.ToString().PadLeft(2)).Concat(ntag);
				var line = string.Join(",", r);
				sb.WriteLine(line);
			}
		}
	}
}

